#ifndef LOGWIDGET_H
#define LOGWIDGET_H

#include <QWidget>
#include <QDateTime>
#include <QScopedPointer>

class QTextEdit;
class QLineEdit;
class QPushButton;
class QComboBox;
class QCheckBox;
class QVBoxLayout;
class QHBoxLayout;
class QRegularExpressionValidator;

class LogWidget : public QWidget
{
    Q_OBJECT

public:
    explicit LogWidget(QWidget *parent = nullptr);
    ~LogWidget();

    // 日志级别
    enum LogLevel {
        Debug = 0,
        Info = 1,
        Warning = 2,
        Error = 3
    };

public slots:
    void logMessage(LogLevel level, const QString &message);
    void logDebug(const QString &message);
    void logInfo(const QString &message);
    void logWarning(const QString &message);
    void logError(const QString &message);
    void clearLog();

private slots:
    void filterChanged();
    void copySelected();
    void saveLog();

private:
    void setupUI();
    void loadSettings();
    void saveSettings();
    QString levelToString(LogLevel level) const;
    QString formatMessage(LogLevel level, const QString &message) const;
    
    // UI元素
    QTextEdit *logTextEdit;
    QLineEdit *filterLineEdit;
    QComboBox *levelComboBox;
    QCheckBox *autoScrollCheckBox;
    QPushButton *clearButton;
    QPushButton *copyButton;
    QPushButton *saveButton;
    
    // 布局
    QVBoxLayout *mainLayout;
    QHBoxLayout *controlLayout;
    
    // 当前日志级别过滤
    LogLevel currentLevel;
    
    // 消息计数
    int messageCount;
};

#endif // LOGWIDGET_H